import { Component, OnInit } from '@angular/core';

import { Subject } from 'rxjs';
import { BsModalRef } from 'ngx-bootstrap/modal';

@Component({
  template: `
  <div class="alert-box">
    <div class="modal-header">
        <h4 class="modal-title">{{title}}</h4>
        <button type="button" class="close" aria-label="Close" (click)="bsModalRef.hide()">
            <span aria-hidden="true">&times;</span>
        </button>
    </div>
    <div class="modal-body">
      {{message}}
    </div>
    <div class="modal-footer">
        <button type="button" class="btn btn-secondary" (click)="onConfirm()">确认</button>
        <button type="button" class="btn btn-secondary" (click)="onCancel()">取消</button>
    </div>
  </div>
  `
})
export class ConfirmModalComponent implements OnInit {
  title = '确认';
  message = '是否要删除该记录';

  public onClose: Subject<boolean>;

  constructor(private _bsModalRef: BsModalRef) { }

  public ngOnInit(): void {
      this.onClose = new Subject();
  }

  public onConfirm(): void {
      this.onClose.next(true);
      this._bsModalRef.hide();
  }

  public onCancel(): void {
      this.onClose.next(false);
      this._bsModalRef.hide();
  }
}
